package android.material.util;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.material.widget.NavigationView;
import android.view.View;

import hd.util.ScreenHelper;

/**
 * NavigationIcon
 * <p/>
 * Created by haidy on 15/1/2.
 */
public class NavigationIcon {

    /**
     * 绘制导航的图标
     *
     * @param canvas canvas
     * @param view   view
     * @param type   类型
     */
    public static void drawNavigation(Canvas canvas, View view, int type) {
        canvas.save();
        int height = view.getHeight();
        int size = ScreenHelper.dp2px(view.getContext(), 20);
        int left = ScreenHelper.dp2px(view.getContext(), 16);
        int top = (view.getHeight() - size) / 2;
        if (type == NavigationView.NAV_ICON) {//导航，三个横杠
            canvas.translate(left, top + size / 2);
            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            paint.setStyle(Paint.Style.FILL);
            paint.setAntiAlias(true);
            paint.setStrokeWidth(ScreenHelper.dp2px(view.getContext(), 2.5f));

            canvas.drawLine(0, 0, size, 0, paint);//中间的线

            int d = ScreenHelper.dp2px(view.getContext(), 6);
            canvas.drawLine(0, -d, size, -d, paint);
            canvas.drawLine(0, d, size, d, paint);
        } else if (type == NavigationView.NAV_BACK) {//返回
            canvas.translate(left, height / 2);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(Color.WHITE);
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
            paint.setStrokeWidth(ScreenHelper.dp2px(view.getContext(), 2.5f));
            float halfWidth = (float) (paint.getStrokeWidth() / 2 / Math.sqrt(2));
            float endX = size / 2 + halfWidth;
            float endY = size / 2 - halfWidth;
            canvas.drawLine(halfWidth, -halfWidth, endX, endY, paint);
            canvas.drawLine(halfWidth, halfWidth, endX, -endY, paint);
            canvas.drawLine((float) (paint.getStrokeMiter() / Math.sqrt(2)), 0, size, 0, paint);
        }
        canvas.restore();
    }
}
